#pragma once

#include "ExecutionSpecification.h"

#include "OccurrenceSpecification.h"

namespace uml {

ExecutionSpecification::ExecutionSpecification(const QString& umlType)
    : NamedElement(umlType) {}

void ExecutionSpecification::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    NamedElement::fromJson(json, errorList);
    InteractionFragment::fromJson(json, errorList);
    finish_ = JsonSerializable::create<OccurrenceSpecification>(json.value("finish"), errorList);

    start_ = JsonSerializable::create<OccurrenceSpecification>(json.value("start"), errorList);

}

void ExecutionSpecification::toJson(QJsonObject& json) {
    NamedElement::toJson(json);
    InteractionFragment::toJson(json);
    if (finish_) {
        QJsonObject finish_json;
        finish_->toJson(finish_json);
        json.insert("finish", finish_json);
    }
    if (start_) {
        QJsonObject start_json;
        start_->toJson(start_json);
        json.insert("start", start_json);
    }
}

/// <summary>
/// finish getter
/// References the OccurrenceSpecification that designates the finish of the Action
/// or Behavior.
/// </summary>
shared_ptr<OccurrenceSpecification> ExecutionSpecification::finish() const {
    return finish_;
}

/// <summary>
/// finish setter
/// References the OccurrenceSpecification that designates the finish of the Action
/// or Behavior.
/// </summary>
void ExecutionSpecification::setFinish(shared_ptr<OccurrenceSpecification> value) {
    finish_ = value;
}

/// <summary>
/// start getter
/// References the OccurrenceSpecification that designates the start of the Action
/// or Behavior.
/// </summary>
shared_ptr<OccurrenceSpecification> ExecutionSpecification::start() const {
    return start_;
}

/// <summary>
/// start setter
/// References the OccurrenceSpecification that designates the start of the Action
/// or Behavior.
/// </summary>
void ExecutionSpecification::setStart(shared_ptr<OccurrenceSpecification> value) {
    start_ = value;
}

} // namespace uml
